from django.db import models
from apitower.models import *
from apilogin.models import *


class Asset(models.Model):
    """
        @author: 成晨
        @date: 10/15/2018
        本模型为资产名称，录入所有的资产，资产名为唯一
        @整理： 董海明
    """
    asset_name = models.CharField(max_length=200, unique=True)
    price = models.FloatField(default=0)


class Interchange(models.Model):
    """
        @author: 成晨
        @date: 10/15/2018
        本模型为每个房间的资产数量，以及所放资产
        @ 整理： 董海明
    """
    room = models.ForeignKey(Room, on_delete=models.CASCADE)
    asset = models.ForeignKey(Asset, on_delete=models.CASCADE)
    asset_num = models.IntegerField()


class PurchaseForm(models.Model):
    """
        @author: 董海明
        @date: 10/23/2018
        本模型为采购记录表
            需要用到的内容：记录人、房间、json文件、日期（自动添加）
    """
    username = models.ForeignKey(User, on_delete=models.CASCADE)
    dep_location = models.ForeignKey(Room, on_delete=models.CASCADE)
    json_file = models.CharField(max_length=1500)
    cg_date = models.DateTimeField(auto_now_add=True)


class Purchase(models.Model):
   """
        @author: 董海明
        @date: 10/23/2018
        本模型为采购详情记录
            需要的内容：资产名、数量、单价、记录人、采购人、存放位置、备注
   """
   purchase = models.ForeignKey(PurchaseForm, on_delete=models.CASCADE)
   as_name = models.CharField(max_length=100)
   as_num = models.IntegerField()
   jprice = models.FloatField()
   lr_user = models.CharField(max_length=30)
   cg_user = models.CharField(max_length=30)
   in_place = models.CharField(max_length=30)
   remark = models.CharField(max_length=300)
   lr_date = models.DateTimeField(auto_now_add=True)


class Receive(models.Model):
    """
        @author: 董海明
        @date: 10/23/2018
        领用json表
            需要保存的内容有：记录人、json文件、放入位置
    """
    lr_user = models.ForeignKey(User, on_delete=models.CASCADE)
    json_file = models.CharField(max_length=1500)
    dep_location = models.ForeignKey(Room, on_delete=models.CASCADE)
    lr_date = models.DateTimeField(auto_now_add=True)


class InsideReceive(models.Model):
    """
        @author: 董海明
        @Date: 10/23/2018
        领用记录表，用来记录领用的各种信息方便查询
            领用的数据以字典传入后台，后台再按格式写入数据库
            需要用到的内容：
                资产名、数量、单价、领用人、记录人、领出位置(out_place)、放入位置(in_place)、备注

    """
    receive = models.ForeignKey(Receive, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    jprice = models.FloatField()
    ly_user = models.CharField(max_length=30)
    jl_user = models.CharField(max_length=30)
    out_place = models.CharField(max_length=50)
    in_place = models.CharField(max_length=50)
    ly_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)


class RepairForm(models.Model):
    """
        @author: 董海明
        @10/23/2018
        本模型为资产报修记录表，记录报修json文件
            需要用到的内容有 记录人、json文件、报修房间、日期（自动）
    """
    username = models.ForeignKey(User, on_delete=models.CASCADE)
    bx_room = models.ForeignKey(Room, on_delete=models.CASCADE)
    json_file = models.CharField(max_length=1500)
    bx_date = models.DateTimeField(auto_now_add=True)


class RepairsRecord(models.Model):
    """
        @author: 董海明
        @10/23/2018
        报修记录表，记录每一次的报修的单据内容
            报修以字典的形式传入后台，后台写入数据库
                需要用到的内容：
                    资产名、数量、报修人、报修房间、备注
    """
    repair = models.ForeignKey(RepairForm, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    bx_user = models.CharField(max_length=30)
    bx_room = models.CharField(max_length=30)
    lr_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)


class DamageForm(models.Model):
    """
        @author: 董海明
        @date: 10/23/2018
        本模型为资产报损表，记录每条报损信息
            需要用到的内容：记录人、报损房间、json文件、日期（自动添加）
    """
    username = models.ForeignKey(User, on_delete=models.CASCADE)
    bs_room = models.ForeignKey(Room, on_delete=models.CASCADE)
    json_file = models.CharField(max_length=1500)
    bs_date = models.DateTimeField(auto_now_add=True)


class DamageRecord(models.Model):
    """
        报损记录表，记录每一次的报损的单据内容
            报损以字典的形式传入后台，后台写入数据库
                需要用到的内容
                    资产名、数量、报损人、报损房间、备注
    """
    damage = models.ForeignKey(DamageForm, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    bs_user = models.CharField(max_length=30)
    bs_room = models.CharField(max_length=30)
    lr_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)













